{extends file="../global.html"}
{block name=body}
 <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="{url('/run/goods/index')}" method="get">
                <div class="layui-form-pane" style="text-align: center;">
                  <div class="layui-form-item" style="display: inline-block;">
                    <!-- <label class="layui-form-label xbs768">日期范围</label>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
                    </div>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
                    </div> -->
                    <div class="layui-input-inline">
                      <input type="text" name="goods_name" value="{$goods_name}"  placeholder="请输入商品名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                        <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                    </div>
                  </div>
                </div> 
            </form>
            <xblock><button class="layui-btn" onclick="window.location.href='add'"><i class="layui-icon">&#xe608;</i>添加</button><span class="x-right" style="line-height:40px">共有数据：{$num} 条</span></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        
                        
                        <th>
                            商品名
                        </th>
                        <th>
                            所属品牌
                        </th>
                        <th>
                            封面图片
                        </th>
                        <th>
                            车身结构
                        </th>
                        <th>
                            商品年份
                        </th>
                        <th>
                            商品排量
                        </th>
                        <th>
                           商品配置信息
                        </th>
                        <th>
                           厂商指导价(万)
                        </th>
                        <th>
                           首付(万)
                        </th>
                        <th>
                           月供(元)
                        </th>
                        
                        <th>
                           尾款购车(元)
                        </th>
                         <th>
                          是否在首页显示
                        </th>
                         <th>
                          商品状态
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                {foreach $res as $v}
                    <tr class="del_{$v.goods_id} tr">
                        
                        
                        <td>
                            <u style="cursor:pointer" onclick="member_show('张三','member-show.html','10001','360','400')">
                               <strong><span style="color: red;">{$v.goods_name}</span></strong>
                            </u>
                        </td>
                        
                        <td >
                            <b>{foreach $type as $value}
                                {if $v.type_id == $value.type_id }
                                    {$value.type_name}
                                {/if}
                            {/foreach}</b>
                        </td>

                        <td >
                            <img src="{$absroot}{$v.goods_pic}" width="100" alt="">
                        </td>
                        <td>
                            {$v.goods_model_car}
                        </td>
                        <td >
                            {$v.goods_model}
                        </td>

                        <td >
                             {$v.goods_describe}
                        </td>
                        <td>
                            {$v.goods_car}
                        </td>
                        <td >
                         {$v.goods_price}万
                           
                        </td>
                        <td >
                        {$v.goods_payment}万
                           
                        </td>
                        <td>
                             {$v.goods_month}元
                        </td>
                       
                        <td >
                           {$v.goods_retainage}元
                        </td>
                         <input type="hidden" class="car_input values-{$v.goods_id}" value="{$v.goods_show}">
                         <td class="td-status">
                            
                            <span class="layui-btn {if $v.goods_show==0} layui-btn-normal {else} layui-btn-danger {/if}layui-btn-mini show-{$v.goods_id}" onclick="show({$v.goods_id},{$v.goods_show})">{if $v.goods_show==0}显示{else}不显示{/if}</span>
                         
                        </td>
                        <input type="hidden" class="car_input value-{$v.goods_id}" value="{$v.goods_status}">
                          <td class="td-status">

                            <span class="layui-btn {if $v.goods_status==0} layui-btn-normal {else} layui-btn-danger {/if}layui-btn-mini state-{$v.goods_id}" onclick="state({$v.goods_id})">{if $v.goods_status==0}上架{else}补货中{/if}</span>
                         
                        </td>
                        <td class="td-manage" style="width:3%">
                             <a title="商品配置" href="{url('/run/Configure/add/goods_id/'|cat:$v.goods_id)}"
                            class="ml-5" style="text-decoration:none">
                                <i class="layui-icon">&#xe620;</i>
                            </a>
                              <a title="亮点解说" href="{url('/run/Highlights/add/goods_id/'|cat:$v.goods_id)}"
                            class="ml-5" style="text-decoration:none">
                                <i class="layui-icon">&#xe60b;</i>
                            </a>
                            <a title="编辑" href="{url('/run/goods/edit/id/'|cat:$v.goods_id)}"
                            class="ml-5" style="text-decoration:none">
                                <i class="layui-icon">&#xe642;</i>
                            </a>
                           
                            <a title="删除" href="javascript:typeDel({$v.goods_id})"  
                            style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                   {/foreach}
                </tbody>

            </table>
            <div align="center">
                    {$res->render()}
            </div>
            <!-- 右侧内容框架，更改从这里结束 -->
          </div>
      
        <script type="text/javascript">
        // DOM元素加载完毕执行
        // $(function(){
            // var inputDoms = $('body .car_input');

            // for(var i=0, length = inputDoms.length; i<=length; i++){
            //     var inputDom = $(inputDoms[i]);
            //     var status = parseInt(inputDom.val());
            //     var statusDom = inputDom.siblings('.td-status');
            //     if( status === 0 ){
            //         statusDom.find('span').addClass('layui-btn-normal').text('上架').removeClass('layui-btn-danger');;
            //     } else {
            //         statusDom.find('span').addClass('layui-btn-danger').text('补货中').removeClass('layui-btn-normal');
            //     }
                
            // }
            function typeDel(goodsid){
                    if(confirm('确定要删除？')==true){
                       $.ajax({
                        type:"post",
                        data:{ goods:goodsid},
                        url:"{url('run/goods/ajaxDel')}",
                        success:function(msg){
                            if(msg==true){
                                 $('.del_'+goodsid).remove();        
                            }
                            else{
                                alert('删除失败');
                            }
                         },
                         error:function(){
                                
                        }

                     })
                    }
              }
        function state(goodsid){
            var sta = $('.state-'+goodsid).text();
            var value = $('.value-'+goodsid).val();
            // alert(value);
              $.ajax({
                        type:"post",
                        data:{ goods:goodsid,goodsStatus:value},
                        url:"{url('run/goods/ajaxState')}",
                        success:function(msg){
                            // alert(msg);
                            if(msg==true){
                                if(sta == '补货中'){
                                   $('.state-'+goodsid).text('上架').removeClass('layui-btn-danger').addClass('layui-btn-normal');
                                      $('.value-'+goodsid).val('0')   
                                }else{
                                     $('.state-'+goodsid).text('补货中').removeClass('layui-btn-normal').addClass('layui-btn-danger'); 
                                      $('.value-'+goodsid).val('1')
                                }
                            }
                            else{
                                alert('删除失败');
                            }
                         },
                         error:function(){
                                
                        }

                     })


         }


         function show(goodsid,goods_show){
             var sta = $('.show-'+goodsid).text();
               var value = $('.values-'+goodsid).val();
             // alert(goods_show);
              $.ajax({
                        type:"post",
                        data:{ goods:goodsid,goodsShow:value},
                        url:"{url('run/goods/ajaxShow')}",
                        success:function(msg){
                            // alert(msg);
                            if(msg==true){
                                if(sta == '不显示'){
                                   $('.show-'+goodsid).text('显示').removeClass('layui-btn-danger').addClass('layui-btn-normal');
                                      $('.values-'+goodsid).val('0');
                                }else{
                                     $('.show-'+goodsid).text('不显示').removeClass('layui-btn-normal').addClass('layui-btn-danger'); 
                                      $('.values-'+goodsid).val('1');
                                }
                            }
                            else{
                                alert('修改失败');
                            }
                         },
                         error:function(){
                                
                        }

                     })

         }
        // });


             
          
   
          
        </script>
{/block}